$.fn.moduleSet = function (opt) {
    var setting = {
        button: [
            {text: '编辑', callback: function () {}, iconfont: 'fa-edit'},
            {text: '美化', callback: function () {}, iconfont: 'fa-paint-brush'},
            {text: '删除', callback: function () {}, iconfont: 'fa-trash'}
        ],
    }
    var options = $.extend({}, setting, opt);
    var M = {};
    var _this = this;

    // 初始化
    M.init = function () {
        $(_this).css('position', 'relative');
        M.createStyle();
        M.createElem(function () {
            M.initShowModule();
        });
    }

    // 显示方法
    M.initShowModule = function () {
        $(_this).mouseenter(function (e) {
            e.preventDefault();
            $(_this).find('.panel-module-box').fadeIn(100);
        }).mouseleave(function (e) {
            e.preventDefault();
            $(_this).find('.panel-module-box').fadeOut(50);
        })
    }
    
    // 创建样式
    M.createStyle = function () {
        if ($('#panel-style').length > 0)
            return;
        var style = '<style id="panel-style">\n\
                .panel-module-box{display:none;}\n\
                .panel-module-box .panel-module-mask{min-height:20px; position: absolute; z-index: 9999; left: 0; right: 0; bottom: 0; top: 0; background: #00a65a; opacity: .7; border: 2px dashed #00733e; cursor: move; }\n\
                .panel-module-box .title{ position: absolute; right:left; top:0; z-index: 9999;font-weight: bold; color: #fff !important; padding-left:15px}\n\
                .panel-module-box .btn-group{ position: absolute;left:50%;top:50%; z-index: 9999;margin-top:-16px;margin-left:-30px}\n\
                .panel-module-box .btn{ cursor: pointer;}\n\
                </style>';
        $($('head')[0]).append(style);
    }

    // 创建elem
    M.createElem = function (callback) {
        if ($(_this).find('.btn-group').length > 0)
            return;
        var btnGroup = '';
        for (var i = 0; i < options.button.length; i++) {
            btnGroup += '<button class="btn btn-default panel-module-button"><i class="fa ' + options.button[i].iconfont + '"></i>' + options.button[i].text + '</button>';
            // 绑定事件
            M.createEvent(i);
        }
        var title =$(_this).find('label.plugins-label').text();
        var elem = '<div class="panel-module-box"><div class="panel-module-mask"></div><div class = title><h4>' + title + '</h4></div><div class="btn-group">' + btnGroup + '</div></div>';
        $(_this).append(elem);
        // 创建后回调
        callback && typeof (callback) == 'function' && callback(this);
    }

    // 创建事件
    M.createEvent = function (index) {
        $(_this).delegate('button.panel-module-button:eq(' + index + ')', 'click', function (e) {
            e.preventDefault();
            !!options.button[index].callback && typeof (options.button[index].callback) == 'function' && options.button[index].callback(this);
        })
    }
    M.init();
}